package com.ruoyi.web.controller.labormgr;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.labormgr.domain.Operation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.labormgr.domain.LaborEmploy;
import com.ruoyi.labormgr.service.ILaborEmployService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 劳动力情况Controller
 *
 * @author ruoyi
 * @date 2021-07-08
 */
@Api("劳动力管理")
@RestController
@RequestMapping("/labormgr/labor")
public class LaborEmployController extends BaseController
{
    @Autowired
    private ILaborEmployService laborEmployService;

    /**
     * 查询劳动力情况列表
     */
    @ApiOperation("查询劳动力情况列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:list')")
    @GetMapping("/list")
    public TableDataInfo list(LaborEmploy laborEmploy)
    {
        startPage();
        List<LaborEmploy> list = laborEmployService.selectLaborEmployList(laborEmploy);
        return getDataTable(list);
    }

    /**
     * 导出劳动力情况列表
     */
    @ApiOperation("导出劳动力情况列表")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:export')")
    @Log(title = "劳动力情况", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LaborEmploy laborEmploy)
    {
        List<LaborEmploy> list=new ArrayList();
        //通过id来取
        Long a[]=laborEmploy.getLaborEmployIds();
        for(int i=0;i<a.length;i++) {
            LaborEmploy list1 = laborEmployService.selectLaborEmployById(a[i]);
            list.add(list1);
        }


        ExcelUtil<LaborEmploy> util = new ExcelUtil<LaborEmploy>(LaborEmploy.class);
        return util.exportExcel(list, "劳动力情况数据");
    }

    /**
     * 获取劳动力情况详细信息
     */
    @ApiOperation("获取劳动力情况详细信息")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:query')")
    @GetMapping(value = "/{laborEmployId}")
    public AjaxResult getInfo(@PathVariable("laborEmployId") Long laborEmployId)
    {
        return AjaxResult.success(laborEmployService.selectLaborEmployById(laborEmployId));
    }

    /**
     * 新增劳动力情况
     */
    @ApiOperation("新增劳动力情况")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:add')")
    @Log(title = "劳动力情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LaborEmploy laborEmploy)
    {
        return toAjax(laborEmployService.insertLaborEmploy(laborEmploy));
    }

    /**
     * 修改劳动力情况
     */
    @ApiOperation("修改劳动力情况")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:edit')")
    @Log(title = "劳动力情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LaborEmploy laborEmploy)
    {
        return toAjax(laborEmployService.updateLaborEmploy(laborEmploy));
    }

    /**
     * 删除劳动力情况
     */
    @ApiOperation("删除劳动力情况")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:remove')")
    @Log(title = "劳动力情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{laborEmployIds}")
    public AjaxResult remove(@PathVariable Long[] laborEmployIds)
    {
        return toAjax(laborEmployService.deleteLaborEmployByIds(laborEmployIds));
    }

    /**
     * 审核劳动力情况
     */
    @ApiOperation("审核劳动力情况")
    @ResponseBody
    @PreAuthorize("@ss.hasAnyPermi('labormgr:labor:review1,labormgr:labor:review2')")
    @Log(title = "劳动力情况", businessType = BusinessType.UPDATE)
    @PutMapping("/review")
    public AjaxResult review(@RequestBody LaborEmploy laborEmploy)
    {
        return toAjax(laborEmployService.reviewLaborEmploy(laborEmploy));
    }

    /**
     * 获取操作编号及名称
     */
    @ApiOperation("获取操作编号及名称")
    @ResponseBody
    @PreAuthorize("@ss.hasPermi('labormgr:labor:operation')")
    @GetMapping("/operation")
    public TableDataInfo operation()
    {
        //startPage();
        List<LaborEmploy> list = laborEmployService.getOperation();
        List<Operation> operationList = new ArrayList<>();
        for (LaborEmploy labor:list) {
            Long id = labor.getOperationId();
            String name = labor.getOperationName();
            Operation operation = new Operation(id,name);
            operationList.add(operation);
        }
        return getDataTable(operationList);
    }

}
